﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>title</title>
    <meta content="$homeContent.getURI('favicon.ico')" itemprop="image">
    <link rel="shortcut icon" href="$homeContent.getURI('favicon.ico')" type="image/x-icon"/>
    <link href="/assets/style.css" rel="stylesheet" type="text/css" /> 
    <link href="/assets/wallpaper.css" rel="stylesheet" type="text/css" /> 
    <link href="/assets/miniui/portal/portal.css" rel="stylesheet" type="text/css" />  
            
    <script src="/assets/miniui/boot.js" type="text/javascript"></script>
    <link href="/assets/miniui/miniui/themes/blue/skin.css" rel="stylesheet" type="text/css" />  
           
    <script src="/assets/echarts-2.2.1/build/dist/echarts-all.js" type="text/javascript"></script>
            
    <script src="/assets/js/util/util.js" type="text/javascript"></script>
    <script src="/assets/jcookie/jquery.cookie.js" type="text/javascript"></script>
    <script src="/assets/miniui/portal/Portal.js" type="text/javascript"></script>
    <script src="/assets/zdialog/zDialog.js" type="text/javascript"></script>
    <script src="/assets/zdialog/zDrag.js" type="text/javascript"></script>





@*    <script src="$adminContent.getURI('assets/swfupload/swfupload.js')" type="text/javascript"></script>
    <script src="$adminContent.getURI('assets/Plupload/demo/js/plupload/plupload.full.min.js')"></script>
    <script src="$adminContent.getURI('assets/Plupload/demo/js/qiniu.js')"></script>*@
    <link href="/assets/xtjm.css" rel="stylesheet" type="text/css" />
    <link href="/assets/xtjm_home.css" rel="stylesheet" type="text/css" />
    <style>
        .my-mini-tree .mini-tree-icon {
            background-color: rgba(140, 178, 226, 0);
        }
    </style>

</head>

<body>
    <div class="mini-splitter" style="width:100%;height:100%;border-bottom:0;">
    <div size="240" showCollapseButton="true">
        <div class="mini-toolbar" style="border-top:0;border-left:0;border-right:0;">
            <form id="fk">
                <table style="width:100%;">
                        <tr>
                        <td style="white-space:nowrap;">
                            <label style="font-family:Verdana;">名称: </label>
                            <input name="key" class="mini-textbox" />
                            <a class="mini-button" iconCls="icon-search" onclick="onSearch()">查询</a>
                        </td>
                        </tr>
                </table>
            </form>
        </div>

        <div class="mini-fit">
	        <ul id="tree1" class="mini-tree my-mini-tree" url="/Sys/MenuTree" 
	        style="width:200px;padding:5px;overflow:auto;" showTreeIcon="true" textField="text" idField="id" parentField="pid" 
	        resultAsTree="false" showCheckBox="true" checkRecursive="true" expandOnLoad="true"  contextMenu="#contextMenu">
	        </ul>
        </div> 
         <ul id="contextMenu" class="mini-contextmenu" onbeforeopen="onBeforeOpen">
    		<li name="sy" iconCls="icon-upload" onclick="onItemClick">上移</li>	
			<li name="xy" iconCls="icon-download" onclick="onItemClick">下移</li>
			<li name="sw" iconCls="icon-upgrade" onclick="onItemClick">首位</li>
			<li name="mw" iconCls="icon-downgrade" onclick="onItemClick">末位</li>	
    		<li iconCls="icon-remove" >关闭</li>
      </ul>
    </div>

    <div showCollapseButton="true">
       <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;">
        <table style="width:100%;">
          <tr>
            <td style="width:100%;">

            </td>
            <td style="white-space:nowrap;">
                <a class="mini-button" iconCls="icon-add" onclick="menu_add">新增</a>
                <a class="mini-button" iconCls="icon-close" onclick="menu_delete">删除</a>
                <a class="mini-button" iconCls="icon-save" onclick="menu_save">保存</a>
            </td>
          </tr>
        </table>
       </div>
        
       <div style="width:100%;height:100%;">
       <div class="mini-tabs" activeIndex="0"  style="margin:5px;">
       
          <div title="菜单信息">
            <input id="selectNode" type="hidden" value="" />
            <form id="form1">
                <table style="line-height:20px;" cellpadding=5>
                    <tr>
                        <td style="width:80px;">图标：</td>
                        <td>
                            <input id="MenuIcon" name="MenuIcon" class="mini-textbox" style="width:320px;" required="true" />
                        </td>
                    </tr>
                    <tr id = "menu_id_tr">
                        <td>菜单编号：</td>
                        <td>
                            <input id="MenuId" name="MenuId" allowInput="false" class="mini-spinner" value="0" vtype="int" style="width:320px;" />
                        </td>             
                    </tr>
                    <tr>
                        <td>菜单名称：</td>
                        <td>
                            <input id="MenuName" name="MenuName" class="mini-textbox" style="width:320px;" required="true" vtype="maxLength:20"/>
                        </td>             
                    </tr>
                    <tr>
                        <td>显示顺序：</td>
                        <td>
                            <input id="DisplayOrder" name="DisplayOrder" style="width:320px;" class="mini-spinner" vtype="int" value="0" required="true" onvaluechanged="onValueChanged" />
                        </td>             
                    </tr>
		            <tr>
                        <td>父菜单：</td>
                        <td>
                            <input id="ParentId" name="ParentId" class="mini-buttonedit" style="width:320px;" onbuttonclick="onButtonEdit" allowInput="false"/> 
                        </td>             
                    </tr>

                    <tr>
                        <td>菜单地址：</td>
                        <td>
                            <input id="MenuUrl" name="MenuUrl" class="mini-textbox" style="width:320px;" vtype="maxLength:255"/>
                        </td>             
                    </tr>
        
                    <tr>
                        <td>备注：</td>
                        <td>
                            <input id="Remark" name="Remark" class="mini-textarea" style="width:400px;" vtype="maxLength:255"/>
                        </td>             
                    </tr>
        
                    <tr id="createTime_tr">
                        <td>创建时间：</td>
                        <td>
                           <input id="CreateTime" name="CreateTime" class="mini-datepicker" style="width:200px;"nullValue="null"
                            allowInput="false" format="yyyy-MM-dd H:mm:ss" readonly="true"/>
              
                        </td>             
                    </tr>
                </table>
            </form>
          </div>
       </div>
       </div>
    </div>        
</div>

</body>
<script type="text/javascript">
    mini.parse();
 
	 
	 var tree = mini.get("tree1");
	 tree.selectNode (tree.getRootNode());
	 

     //树节点点击事件处理
	 tree.on("nodeselect", function (e) {

	     $.ajax({
	         url: "/Sys/GetMenu",
	         data: { id: e.node.id },
	         type: "post",
	         success: function (obj) {

	             var selectPNode = tree.getParentNode(e.node);
	             var rootNode = tree.getRootNode();

	             var o = mini.decode(obj);
	             var form = new mini.Form("form1");
	             form.setData(o);
	             form.setChanged(false);
	             mini.getbyName("MenuIcon").setValue(o.MenuIcon);
	             mini.getbyName("MenuName").setValue(o.MenuName);
	             mini.getbyName("DisplayOrder").setValue(o.DisplayOrder);
	             mini.getbyName("ParentId").setValue(o.ParentId);
	             mini.getbyName("MenuUrl").setValue(o.MenuUrl);
	             mini.getbyName("Remark").setValue(o.Remark);

	             var btnEdit = mini.get("ParentId");

	             if (selectPNode != rootNode) {
	                 btnEdit.setText(selectPNode.text);
	                 btnEdit.setValue(selectPNode.id);
	             }
	             else {
	                 btnEdit.setText("");
	                 btnEdit.setValue("0");
	             }

	             $("#selectNode").val(e.node.id);

	         },
	         error: function (jqXHR, textStatus, errorThrown) {
	           
	         }
	     });

	 });
	 
     //添加菜单
     function menu_add()
	 {
        var form = new mini.Form("form1");
        form.clear();
        form.setChanged(false);

        mini.getbyName("DisplayOrder").setValue(0);


        if ($("#selectNode").val().length > 0) {

            var select_node = tree.getNode($("#selectNode").val());

            var btnEdit = mini.get("ParentId");

            btnEdit.setText(select_node.text);
            btnEdit.setValue(select_node.id);
        }



	 };
	 
     //菜单删除
	 function menu_delete()
	 {
		 if(tree.getValue() == null || tree.getValue() == '')
		 {
		 	mini.alert("请选中需要删除的菜单!");
		 	return;
		 }
		 
	     mini.confirm("确定删除记录？", "确定？",
            function (action) {
                if (action == "ok") {
                    $.ajax({
                        url: "/Sys/DeleteMenu",
                        data: { ids: tree.getValue() },
                        type: "post",
                        success: function (obj) {

                            tree.load("/Sys/MenuTree");

                            mini.alert("删除成功");
                        },
                        error: function (jqXHR, textStatus, errorThrown) {
                          
                        }
                    });
                }
            }
        ); 
	 };
	 
     //菜单保存
	 function menu_save()
	 {
	 	var form = new mini.Form("#form1");

	 	if (form.validate()) {


	 	    var data = form.getData();
	 	    var json = mini.encode(data);

	 	    console.log(json);

	 	    $.ajax({
	 	        url: "/Sys/EditMenu",
	 	        data: {
	 	            json: json
	 	        },
	 	        type: "post",
	 	        success: function (obj) {

	 	            tree.load("/Sys/MenuTree");

	 	            $("#selectNode").val(obj.menuId);
	 	            var select_Node = tree.getNode($("#selectNode").val());
	 	            tree.selectNode(select_Node);

	 	            mini.alert("保存成功");

	 	        },
	 	        error: function (jqXHR, textStatus, errorThrown) {
	 	         
	 	        }
	 	    });
	 	}
	 };
	 
     //菜单树过滤
	 function onSearch()
	 {
	 	var form = new mini.Form("#fk");
	 	var data = form.getData();     
	 	var key = mini.getbyName("key").getValue();

	 	
	 	var msgid = mini.loading("数据查询中，请稍后......");
	 	$.ajax({
	 	    url: "$adminContent/adminScreen.do?action=SysMenuAction&event_submit_do_search_tree_by_key=method",
	 	    data: { key: key },
	 	    type: "post",
	 	    success: function (text) {

	 	        var data = mini.decode(text);
	 	        tree.loadList(data);
	 	        tree.expandAll();
	 	        mini.hideMessageBox(msgid);
	 	    },
	 	    error: function (jqXHR, textStatus, errorThrown) {
	
	 	    }
	 	});
	 	
	 }
	 
    //选择父节点编辑
	function onButtonEdit(e) {
	    var btnEdit = this;



	    mini.open({
	        url: "/Sys/TreeMenuEdit?nodeid=" + $("#selectNode").val(),
	        showMaxButton: false,
	        allowResize: false,       //允许尺寸调节
	        title: "选择父节点",
	        width: 350,
	        height: 350,
	        ondestroy: function (action) {
	            if (action == "ok") {
	                var iframe = this.getIFrameEl();

	                var data = iframe.contentWindow.GetData();

	                data = mini.clone(data);
	                if (data) {
	                    btnEdit.setValue(data.id);
	                    btnEdit.setText(data.text);
	                }
	            }
	            else if(action == "cancel") {
	                btnEdit.setValue("");
	                btnEdit.setText("");
	            }


	        }
	    });

	}

	$("#menu_id_tr,#createTime_tr").hide();
	
	
	function onValueChanged(e){

      var spEdit = mini.get("displayOrder");
      if(spEdit.getValue()==100){
        spEdit.setValue(0); 
      } 
   }

   function onItemClick(e) {
           var item = e.sender;
           var node = tree.getSelectedNode(); 
           var type;
           var pid ;
           if(item.getText()=="上移"){
           	   type="sy";
           }else if (item.getText()=="下移"){
               type="xy";
           }else if(item.getText()=="首位"){
           	   type="sw"; 
           }else{
               type="mw";
           }

           if(node.pid==null){ //一级菜单的父节点页面上没有提供
              pid ='0';
           }else{
              pid = node.pid;
           }

           var parms = "&id="+node.id+"&pid="+pid+"&type="+type;
           jQuery.ajax({
            url: "$adminContent/adminScreen.do?action=SysMenuAction&event_submit_do_move=method"+parms,
            cache: false,
            dataType: "text",
            success: function (obj) {
            	tree.load("$adminContent/adminScreen.do?action=SysMenuAction&event_submit_do_menu_query=method");
            },
            error: function (jqXHR, textStatus, errorThrown) {
	             mini.alert("出现异常，请重试或与管理员联系！");
	        }
        	});  
    }

  function onBeforeOpen(e) {
    var menu = e.sender;
    var tree = mini.get("tree1");

    var node = tree.getSelectedNode();
    if (!node) {
        e.cancel = true;
        e.htmlEvent.preventDefault();
        return;
    }
    var parentNode = tree.getParentNode(node);
    var childNode = tree.getChildNodes (parentNode);
    var syItem = mini.getbyName("sy", menu);
    var xyItem = mini.getbyName("xy", menu);
    var swItem = mini.getbyName("sw", menu);
    var mwItem = mini.getbyName("mw", menu);
  
  	var index;//选中节点的下标
 
    if(childNode.length==1){
        syItem.disable();
        xyItem.disable();
        swItem.disable();
        mwItem.disable();
    }else{
     	for(var i=0;i<childNode.length;i++){
    		if(node ==childNode[i]){
    			index =i;
    			break;
    		}
   		}
    	if(index==0){
    		syItem.disable();
    		swItem.disable();
    		xyItem.enable();
    		mwItem.enable();
    	}else if(index ==childNode.length-1){
    		 xyItem.disable();
    		 mwItem.disable();
    		 syItem.enable();
    		 swItem.enable();
    	}else{
    		syItem.enable();
       		xyItem.enable();
        	swItem.enable();
        	mwItem.enable();
    	}
    }
}    
	
</script>



</html>



